class Admin::SessionsController < ApplicationController
  layout 'admin'
  before_action :set_staffer, only:[:create]
  def new

  end

  def create
    status = AuthenticateStafferService.call(@staffer, params[:password])
    if status.success?
      session[:admin_id] = @staffer.id
      redirect_to stores_path, notice: status.message
    else
      redirect_to new_admin_session_path, notice: status.message
    end
  end

  def destroy
    reset_session
    redirect_to new_sessions_path
  end

  private
  def set_staffer
    @staffer = Staffer.find_by(login_name: params[:login_name])
  end
end
